import React from 'react';
// import { connect } from 'dva';
import { Row, Col, Form, Input, Button, Modal, Spin } from 'antd';
import PartSelect from '@/components/PartSelect';
const FormItem = Form.Item;

const formLayout = {
  labelCol: { span: 6 },
  wrapperCol: { span: 14 },
};

const descFormLayout = {
  labelCol: { span: 6 },
  wrapperCol: { span: 14 },
};

// @connect(({ loading }) => ({
//   // loading: loading.effects['#/add'] || loading.effects['#/edit'],
// }))
export default class QuotationUpdate extends React.Component<any, any> {
  handleSubmit = (values: any) => {
    const { onSubmit } = this.props;
    if (typeof onSubmit === 'function') {
      onSubmit(values);
    }
  };

  formRef: any = React.createRef();
  setCurrent = (part?: any) => {
    var PartMtl: any = {};
    PartMtl.partNum = part.partNum;
    PartMtl.partDescription = part.partDescription;
    PartMtl.ium = part.ium;
    this.formRef.current.setFieldsValue({ PartMtl });
  };
  formRender = () => {
    const { formVals = {} } = this.props;

    return (
      <Form {...formLayout} initialValues={formVals} onFinish={this.handleSubmit}>
        <Row gutter={16}>
          <Col span={12}>
            <FormItem name="cailiao" label="物料名称">
              <PartSelect
                name={['PartMtl', 'partNum']}
                noStyle
                width={152}
                required={true}
                placeholder="物料编码"
                setCurrent={this.setCurrent}
                pType="P"
              />
            </FormItem>
          </Col>
          <Col span={12}>
            <FormItem name="id" label="物料编码">
              <Input placeholder="请输入物料编码" />
            </FormItem>
          </Col>
          <Col span={12}>
            <FormItem name="coast" label="成本单价">
              <Input placeholder="请输入成本单价" />
            </FormItem>
          </Col>
          <Col span={12}>
            <FormItem name="count" label="数量">
              <Input placeholder="请输入数量" />
            </FormItem>
          </Col>
          <Col span={12}>
            <FormItem name="time" label="工时">
              <Input placeholder="请输入工时" />
            </FormItem>
          </Col>
          <Col span={12}>
            <FormItem name="timePrice" label="工时单价">
              <Input placeholder="请输入工时单价" />
            </FormItem>
          </Col>
          <Col span={12}>
            <FormItem name="price" label="杂项费用">
              <Input placeholder="请输入杂项费用" />
            </FormItem>
          </Col>
          <Col span={12}>
            <FormItem name="totalPrice" label="总价">
              <Input placeholder="请输入总价" />
            </FormItem>
          </Col>

          <Col span={24} style={{ display: 'flex', justifyContent: 'center' }}>
            <Button type="primary" htmlType="submit">
              确认
            </Button>
          </Col>
        </Row>
      </Form>
    );
  };
  render() {
    const { visible, editStatus, onCancel, loading = false } = this.props;

    const FormRender = this.formRender;

    return (
      <Modal
        title={editStatus ? '编辑报告单' : '创建报告单'}
        width="810px"
        bodyStyle={{ padding: 24 }}
        visible={visible}
        destroyOnClose
        footer={null}
        onCancel={() => onCancel()}
      >
        <Spin spinning={loading}>
          <FormRender />
        </Spin>
      </Modal>
    );
  }
}
